﻿using Lidgren.Network;
using System;

namespace BattleFury.Lib.Network.Packets
{
    [Serializable]
    public class CollisionPacket : IPacket
    {
        PacketCommand IPacket.Command { get { return PacketCommand.Collision; } }
        NetDeliveryMethod IPacket.NetDeliveryMethod
        {
            get { return NetDeliveryMethod.ReliableUnordered; }
        }
        long IPacket.ServerTime
        {
            get { return _servertime; }
        }

        private long _servertime;

        public Guid SourceObjectId { get; set; }
        public Guid TargetObjectId { get; set; }
        public CollisionPacket(long ServerTime)
        { _servertime = ServerTime; }

        public CollisionPacket(long ServerTime, NetIncomingMessage msg)
        {
            _servertime = ServerTime;
            SourceObjectId = new Guid(msg.ReadBytes(16));
            TargetObjectId = new Guid(msg.ReadBytes(16));
        }

        NetOutgoingMessage IPacket.ToOutgoingMessage(NetClient client)
        {
            NetOutgoingMessage msg = client.CreateMessage();
            msg.Write((int)((IPacket)this).Command);
            msg.Write(SourceObjectId.ToByteArray());
            msg.Write(TargetObjectId.ToByteArray());

            return msg;
        }

    }

}